home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-24 | 24.5 KB | 932 lines | [TEXT/MPS ] |
- { UIconDragging.inc1.p}
- { Copyright © 1990, 1991 by Apple Computer, Inc. All rights reserved.}
-
- { Change List:
-
- ddmmyy
- KJS 040391 First integration into Tangram UI
- GAP 010491 Created unit constants and global section
- and moved declarations for icon dimensions
- and insets here from the interface.
- GAP 010491 Moved gOffscreenManager global to implementation
- from the interface.
- GAP 020491 Moved icon height and width back to interface.
- GAP 020491 Fixed infinitely recursive bug in
- TPlaceByNumber.GetCIconHandle.
- GAP 020491 Moved USES UOffscreenManager to implementation.
- GAP 050491 Factored code of TCIconTracker.ICIconTracker into
- multiple nested procedures.
- GAP 050491 In TCIconTracker.ICIconTracker changed setting of portRect
- of fMaxDepthGrafPort from maxDepthGrafPort^.portRect := globRect
- to use of PortSize and MovePortTo.
- GAP 052491 Made changes to convert window to local coordinate in
- TInterViewTracker.TrackMouse>>NextView>>ContainsPt so icons
- can be dragged onto views that are scrolled.
-
-
- End Change List. }
-
-
- { :::::::::::: Interfaces used only by Implementation :::::::::::: }
-
-
- USES
-
- UOffscreenManager;
-
-
-
- { :::::::::::: Unit Constants and Globals :::::::::::: }
-
-
- CONST
-
- kInsetWidth = -2 * kIconWidth;
- kInsetHeight = -2 * kIconHeight;
-
-
- VAR
- gOffscreenManager: TOffscreenManager; { Manages virtual offscreen pixmap for icon dragging. }
-
-
-
- { ::::::::::::::: Unit Initialization :::::::::::::::: }
-
-
- {$S AInit}
- PROCEDURE InitUIconDragging;
-
- VAR
- offscreenSize: Point;
-
- BEGIN {InitUIconDragging}
-
- gOffscreenManager := NIL;
-
- offscreenSize.h := 5 * kIconWidth;
- offscreenSize.v := 5 * kIconHeight;
- NEW(gOffscreenManager);
- FailNIL(gOffscreenManager);
- gOffscreenManager.IOffscreenManager(offscreenSize);
-
- END; {InitUIconDragging}
-
-
- { ::::::::::::: TTrackingView ::::::::::::::::: }
-
-
- {$S ARes}
- FUNCTION TTrackingView.GetInterViewTracker (anIconNumber: IconNumber;
- offset: Point): TInterViewTracker;
-
- { Return the proper tracker to track a icon for this view. }
-
- BEGIN {TTrackingView.GetInterViewTracker}
- GetInterViewTracker := TInterViewTracker(gNoChanges) { Default is no tracker }
- END; {TTrackingView.GetInterViewTracker}
-
-
- {$S ARes}
- PROCEDURE TTrackingView.PlaceIcon (anIconNumber: IconNumber;
- aVPoint: VPoint;
- sense: IconPlacementSense);
-
- { Place an icon in the view at aVPoint in this view's coordinate system. }
-
- BEGIN {TTrackingView.PlaceIcon}
- {$IFC qDebug}
- WRITELN('TTrackingView.PlaceIcon must be overriden!')
- {$ENDC}
- END; {TTrackingView.PlaceIcon}
-
-
- { :::::::::::::::: TCIconTracker ::::::::::::::::::: }
-
- { $S ASelCommand }
- PROCEDURE TCIconTracker.ICIconTracker (itsCmdNumber: CmdNumber;
- itsDocument: TDocument;
- itsView: TView;
- itsScroller: TScroller;
- anIcon: CIconHandle);
-
- VAR
-
- anOSImage: TOSImage;
- iconRect: Rect;
-
- PROCEDURE PreInitialization;
-
- BEGIN {PreInitialization}
-
- fFirstTime := FALSE;
- fLastTime := FALSE;
- fThisTrackPoint := gZeroPt;
- fLastTrackPoint := gZeroPt;
- fCIcon := anIcon;
- fScreenLocusRect.topLeft := gZeroPt;
- fScreenLocusRect.botRight := gZeroPt;
- fMaxDepthGrafPort := NIL;
- fUnderIcon := NIL
-
- END; {PreInitialization}
-
- PROCEDURE SetParentGrafPortAndBounds;
-
- { Set fMaxDepthGrafPort and iconRect as the parent grafport
- and bounds for a TOSImage. }
-
- VAR
-
- globRgn: RgnHandle;
- globRect: Rect;
- globWidth, globHeight: INTEGER;
- theMaxDevice, oldGDevice: GDHandle;
- maxDepthGrafPort: CGrafPtr;
-
- BEGIN {SetParentGrafPortAndBounds}
-
- { Make a parent grafPort for our OSImage of max depth- See Tech Note #120 }
- globRgn := GetGrayRgn;
- globRect := globRgn^^.rgnBBox;
- globWidth := globRect.right - globRect.left;
- globHeight := globRect.bottom - globRect.top;
- theMaxDevice := GetMaxDevice(globRect);
- oldGDevice := GetGDevice;
- SetGDevice(theMaxDevice);
- maxDepthGrafPort := CGrafPtr(NewPtr(SIZEOF(CGrafPort)));
- OpenCPort(maxDepthGrafPort);
- PortSize(globWidth, globHeight); { Set PortRect to cover all devices. }
- MovePortTo(globRect.left, globRect.top);
- fMaxDepthGrafPort := GrafPtr(maxDepthGrafPort);
- SetGDevice(oldGDevice);
-
- { Make sure the iconRect is within the bounds of the corresponding graphics device. }
- iconRect := theMaxDevice^^.gdPMap^^.bounds;
- GlobalToLocal(iconRect.topLeft);
- iconRect.right := iconRect.left + kIconWidth;
- iconRect.bottom := iconRect.top + kIconHeight;
-
- END; {SetParentGrafPortAndBounds}
-
-
- BEGIN {TCIconTracker.ICIconTracker}
-
- { Preinitialize instance variables in case of failure. }
- PreInitialization;
-
- SELF.ICommand(itsCmdNumber, itsDocument, itsView, itsScroller);
-
- { Calculate and set fMaxDepthGrafPort and iconRect. }
- SetParentGrafPortAndBounds;
-
- { Create a TOSImage to store the bits under where the icon
- is plotted, so they can be restored when it moves again. }
- NEW(anOSImage);
- FailNIL(anOSImage);
- anOSImage.IOSImage(fMaxDepthGrafPort, iconRect);
- fUnderIcon := anOSImage;
-
- END; {TCIconTracker.ICIconTracker}
-
-
- {$S ADoCommand}
- PROCEDURE TCIconTracker.Free;
- OVERRIDE;
-
- BEGIN {TCIconTracker.Free}
- DisposIfHandle(fCIcon);
- FreeIfObject(fUnderIcon);
-
- (**** Known Bug: This OUGHT to be necessary, but inclusion will cause the command to crash ***********
-
- { This goes after FreeIfObject(fUnderIcon) since fUnderIcon
- depends on fMaxDepthGrafPort. }
-
- IF fMaxDepthGrafPort <> NIL THEN
- BEGIN
- CloseCPort(CGrafPtr(fMaxDepthGrafPort));
- DisposPtr(Ptr(fMaxDepthGrafPort))
- END;
-
- ******************************************************************************************************)
-
- INHERITED Free
- END; {TCIconTracker.Free}
-
- {$S AFields}
- PROCEDURE TCIconTracker.Fields (PROCEDURE DoToField (fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
-
- BEGIN {TCIconTracker.Fields}
- DoToField('TCIconTracker', NIL, bClass);
- DoToField('fFirstTime', @fFirstTime, bBoolean);
- DoToField('fLastTime', @fLastTime, bBoolean);
- DoToField('fThisTrackPoint', @fThisTrackPoint, bPoint);
- DoToField('fLastTrackPoint', @fLastTrackPoint, bPoint);
- DoToField('fCIcon', @fCIcon, bHandle);
- DoToField('fScreenLocusRect', @fScreenLocusRect, bRect);
- DoToField('fMaxDepthGrafPort', @fMaxDepthGrafPort, bGrafPtr);
- DoToField('fUnderIcon', @fUnderIcon, bObject);
- INHERITED Fields(DoToField);
- END; {TCIconTracker.Fields}
-
-
- { Mouse handling }
- {$S ADoCommand}
- FUNCTION TCIconTracker.TrackMouse (aTrackPhase: TrackPhase;
- VAR anchorPoint, previousPoint, nextPoint: VPoint;
- mouseDidMove: BOOLEAN): TCommand;
- OVERRIDE;
-
- { Note: Subclasses must call this TrackMouse method before executing their TrackMouse code. }
-
- BEGIN {TCIconTracker.TrackMouse}
- TrackMouse := SELF;
- CASE aTrackPhase OF
- trackPress:
- fFirstTime := TRUE;
- trackMove:
- fFirstTime := FALSE;
- trackRelease:
- fLastTime := TRUE
- END
- END; {TCIconTracker.TrackMouse}
-
-
- {$S ADoCommand}
- PROCEDURE TCIconTracker.CIconTrack (nextPoint: Point);
-
- VAR
-
- currPort: GrafPtr;
- oldOnScreenIconRect: Rect; { The rectangle around the icon, screen coordinates, last time through the loop. }
- newOnScreenIconRect: Rect; { The rectangle around the icon, screen coordinates, this time through the loop. }
- oldOffScreenIconRect: Rect; { The rectangle around the icon, offScreen coordinates, last time through the loop. }
- newOffScreenIconRect: Rect; { The rectangle around the icon, offScreen coordinates, this time through the loop. }
-
- PROCEDURE Constrain;
-
- { We do constraining here because TCommand.TrackConstrain gets called at the wrong time. }
-
- VAR
- enclosingRect: Rect;
-
- {$IFC qDebug}
- pnState: PenState;
- {$ENDC}
-
- PROCEDURE ConstrainPtToRect;
-
- BEGIN {ConstrainPtToRect}
-
- IF fThisTrackPoint.h < enclosingRect.left THEN { Constrain Horizontal }
- BEGIN
- {$IFC qDebug}
- IF gIntenseDebugging THEN
- WRITELN('Constrained on LEFT ', fThisTrackPoint.h, ' -> ', enclosingRect.left);
- {$ENDC}
- fThisTrackPoint.h := enclosingRect.left
- END
- ELSE IF fThisTrackPoint.h > enclosingRect.right THEN
- BEGIN
- {$IFC qDebug}
- IF gIntenseDebugging THEN
- WRITELN('Constrained on RIGHT ', fThisTrackPoint.h, ' -> ', enclosingRect.right);
- {$ENDC}
- fThisTrackPoint.h := enclosingRect.right
- END;
-
- IF fThisTrackPoint.v < enclosingRect.top THEN { Constrain Vertical }
- BEGIN
- {$IFC qDebug}
- IF gIntenseDebugging THEN
- WRITELN('Constrained on TOP ', fThisTrackPoint.v, ' -> ', enclosingRect.top);
- {$ENDC}
- fThisTrackPoint.v := enclosingRect.top
- END
- ELSE IF fThisTrackPoint.v > enclosingRect.bottom THEN
- BEGIN
- {$IFC qDebug}
- IF gIntenseDebugging THEN
- WRITELN('Constrained on BOTTOM ', fThisTrackPoint.v, ' -> ', enclosingRect.bottom);
- {$ENDC}
- fThisTrackPoint.v := enclosingRect.bottom
- END
-
- END; {ConstrainPtToRect}
-
- BEGIN {Constrain}
-
- IF fFirstTime THEN
- fLastTrackPoint := fThisTrackPoint
- ELSE
- BEGIN
- enclosingRect := gOffscreenManager.fScreenRect;
- { Adjust for the fact that icons are plotted from upper-left corner. }
- enclosingRect.right := enclosingRect.right - kIconWidth;
- enclosingRect.bottom := enclosingRect.bottom - kIconHeight;
- {$IFC qDebug}
- IF gIntenseDebugging THEN
- BEGIN
- GetPenState(pnState);
- PenMode(patXor);
- FrameRect(enclosingRect);
- FrameRect(enclosingRect);
- SetPenState(pnState)
- END;
- {$ENDC}
- ConstrainPtToRect
- END
- END; {Constrain}
-
- PROCEDURE CalculateRectangles;
-
- { Calculate all the requisite rectangles. }
-
- VAR
- offsetPt: Point;
- locusRect: Rect;
-
- BEGIN {CalculateRectangles}
-
- SetRect(newOnScreenIconRect,
- fThisTrackPoint.h,
- fThisTrackPoint.v,
- fThisTrackPoint.h + kIconWidth,
- fThisTrackPoint.v + kIconHeight);
- SetRect(oldOnScreenIconRect,
- fLastTrackPoint.h,
- fLastTrackPoint.v,
- fLastTrackPoint.h + kIconWidth,
- fLastTrackPoint.v + kIconHeight);
-
- SetRect(newOffScreenIconRect,
- -kInsetWidth,
- -kInsetHeight,
- -kInsetWidth + kIconWidth,
- -kInsetHeight + kIconHeight);
-
- offsetPt := fThisTrackPoint;
- SubPt(fLastTrackPoint, offsetPt);
- oldOffScreenIconRect := newOffScreenIconRect;
- OffsetRect(oldOffScreenIconRect, -offsetPt.h, -offsetPt.v);
-
- locusRect := newOnScreenIconRect;
- InsetRect(locusRect, kInsetWidth, kInsetHeight);
-
- { Note: try aligning bitmaps for extra performance. }
-
- fScreenLocusRect := locusRect;
-
- END; {CalculateRectangles}
-
- PROCEDURE GetLocusFromScreen;
-
- { Get the pixels around the area where the icon will be and store it in the offscreen fScreenLocusImage. }
-
- VAR
- screenLocusRect : Rect;
-
- BEGIN {GetLocusFromScreen}
- screenLocusRect := fScreenLocusRect;
- gOffscreenManager.CopyBitsFromScreen(screenLocusRect, srcCopy, NIL)
- END; {GetLocusFromScreen}
-
- PROCEDURE GetUnderNewIcon;
-
- { Get the pixels where the icon will be plotted from fScreenLocusImage and store in the offscreen fUnderIcon. }
-
- VAR
-
- dstRect : Rect;
- savedPort : GrafPtr;
- savedGDevice : GDHandle;
-
- {$IFC qDebug}
- aRect: Rect;
- {$ENDC}
-
- BEGIN {GetUnderNewIcon}
-
- dstRect := fUnderIcon.fDstRect;
-
- { Save the current grafEnv and set it to this offscreen }
- GetGrafEnv(savedPort, savedGDevice);
- SetOSGrafEnv(fUnderIcon.fParent, dstRect, fUnderIcon.fOSIP);
-
- gOffscreenManager.CopyBitsTo(fUnderIcon.fOSIp^.portBits, fUnderIcon.fOSIp^.portRect, newOnScreenIconRect, srcCopy, NIL);
-
- { Restore old port }
- SetGrafEnv(savedPort, savedGDevice);
-
- {$IFC qDebug}
- IF gIntenseDebugging THEN { Show, in the upper left of the screen, what's under the icon. }
- BEGIN
- SetRect(aRect, 0, 200, kIconWidth, 200 + kIconHeight);
- CopyBits(fUnderIcon.fOSIp^.portBits,
- currPort^.portBits,
- fUnderIcon.fOSIp^.portRect,
- aRect, srcCopy,
- NIL);
- END;
- {$ENDC}
-
- END; {GetUnderNewIcon}
-
- PROCEDURE RestoreUnderOldIcon;
-
- { Put the pixels back in fScreenLocusImage where the icon was plotted. }
-
- VAR
-
- savedPort : GrafPtr;
- savedGDevice : GDHandle;
-
- BEGIN {RestoreUnderOldIcon}
-
- gOffscreenManager.CopyBitsFrom(fUnderIcon.fOSIp^.portBits,
- fUnderIcon.fOSIp^.portRect,
- oldOnScreenIconRect,
- srcCopy,
- NIL);
-
- END; {RestoreUnderOldIcon}
-
- PROCEDURE RenderIcon;
-
- { Plot the icon in the offscreen fScreenLocusImage. }
-
- PROCEDURE QuickDrawStuff;
-
- BEGIN {QuickDrawStuff}
- PlotCIcon(newOnScreenIconRect, fCIcon);
- END; {QuickDrawStuff}
-
- BEGIN {RenderIcon}
- gOffscreenManager.Draw(QuickDrawStuff)
- END; {RenderIcon}
-
- PROCEDURE CopyToScreen;
-
- { Blast the offscreen fScreenLocusImage back to the screen. }
-
- {$IFC qDebug}
- VAR
- screenManagerScreenRect, onScreenRestoreRect: Rect;
- {$ENDC}
-
- BEGIN {CopyToScreen}
-
- gOffscreenManager.CopyBitsToScreen(srcCopy, NIL);
-
- {$IFC qDebug}
- IF gIntenseDebugging THEN { Show, in the upper left of the screen, what's around the icon. }
- BEGIN
- SetRect(onScreenRestoreRect,
- 0,
- 0,
- kIconWidth - (2 * kInsetWidth),
- kIconHeight - (2 * kInsetHeight));
- screenManagerScreenRect := gOffScreenManager.fScreenRect;
- gOffscreenManager.CopyBitsTo(currPort^.portBits,
- onScreenRestoreRect,
- screenManagerScreenRect,
- srcCopy,
- NIL);
- END
- {$ENDC}
-
- END; {CopyToScreen}
-
-
- BEGIN {TCIconTracker.CIconTrack}
- fThisTrackPoint := nextPoint;
- Constrain;
- GetPort(currPort);
- CalculateRectangles;
- GetLocusFromScreen;
- IF NOT fFirstTime THEN
- RestoreUnderOldIcon;
- GetUnderNewIcon;
- IF NOT fLastTime THEN
- RenderIcon;
- CopyToScreen;
- fLastTrackPoint := fThisTrackPoint
- END; {TCIconTracker.CIconTrack}
-
-
- { ::::::::::::: TInterViewTracker ::::::::::::::: }
-
-
- {$S ASelCommand}
- PROCEDURE TInterViewTracker.IInterViewTracker (aTrackingView: TView; offset: Point);
-
- VAR
- anIcon: CIconhandle;
- fi: FailInfo;
-
- PROCEDURE HandleFailure (error: OSErr; message: LONGINT);
-
- BEGIN {HandleFailure}
- SELF.ICIconTracker(cIconTrackerCmd, NIL, NIL, NIL, NIL);
- SELF.Free;
- END; {HandleFailure}
-
- BEGIN {TInterViewTracker.IInterViewTracker}
-
- fTrackingWindow := aTrackingView.GetWindow;
- fTrackingView := aTrackingView;
- fMouseDownOffset := offset;
- fReleasePoint := gZeroVPt;
-
- { Note that this is slightly unusual. Normally you don't do operations that
- allocate memory until after the superclass's initialization method is called.
- However, in this case, TCIconTracker needs the cicn for it to properly complete
- it's initialization. Hence, if the cicn can't be found or allocated, then
- we need to finish the TCicon initialization so that we can free the
- TInterViewTracker. }
-
- CatchFailures(fi, HandleFailure);
- anIcon := SELF.GetCIconHandle;
- Success(fi);
-
- { NOTE: If components ever free their icons we should pass a copy to ICIconTracker
- since TCIconTracker will free it also. }
-
- SELF.ICIconTracker(cIconTrackerCmd, NIL, NIL, NIL, anIcon);
- fViewConstrain := FALSE
-
- END; {TInterViewTracker.IInterViewTracker}
-
-
- {$S AFields}
- PROCEDURE TInterViewTracker.Fields (PROCEDURE DoToField (fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
-
- BEGIN {TInterViewTracker.Fields}
- DoToField('TInterViewTracker', NIL, bClass);
- DoToField('fTrackingWindow', @fTrackingWindow, bObject);
- DoToField('fTrackingView', @fTrackingView, bObject);
- DoToField('fMouseDownOffset', @fMouseDownOffset, bPoint);
- DoToField('fReleasePoint', @fReleasePoint, bVPoint);
- INHERITED Fields(DoToField);
- END; {TInterViewTracker.Fields}
-
-
- {$S ASelCommand}
- FUNCTION TInterViewTracker.GetCIconHandle: CIconHandle;
- BEGIN
- { Subclasses of TInterViewTracker should override this method to get their cicn.
- Some subclasses will store the resource number of the cicn and use the ToolBox
- call "GetCIcon", others will record the cicn's name and used "Get1NamedResource",
- etc. }
-
- GetCIconHandle := NIL;
-
- {$IFC qDebug}
- WriteLn('TInterViewTracker.GetCIconHandle was not overridden');
- {$ENDC}
-
- END;
-
-
- { Mouse handling }
- {$S ADoCommand}
- FUNCTION TInterViewTracker.TrackMouse (aTrackPhase: TrackPhase;
- VAR anchorPoint, previousPoint, nextPoint: VPoint;
- mouseDidMove: BOOLEAN): TCommand;
- OVERRIDE;
-
- VAR
- aPoint: Point;
- savedPort : GrafPtr;
-
- FUNCTION DesktopToLocal (aView: TView; aVPt: VPoint): VPoint;
-
- { Takes aVPt in desktop coordinates and returns a VPoint in aView's coordinates. }
-
- CONST
-
- kFocusFailed = 'Focused Failed in TInterViewTracker.TrackMouse >> DesktopToLocal';
-
- VAR
-
- theVMouse : VPoint;
- theMouse : Point;
- savedPort : GrafPtr;
- oldFocusedView : TView;
- fi : FailInfo;
-
- PROCEDURE HandleFailure (error: OSErr; message: LONGINT);
-
- BEGIN {HandleFailure}
- SetPort(savedPort);
- END; {HandleFailure}
-
- BEGIN {DesktopToLocal}
-
- IF aView <> NIL THEN
- BEGIN
-
- { When fView = NIL we're "focused" on the desktopPort.
- So save it before we focus on a view, so it can be restored. }
-
- GetPort(savedPort); { If we don't do this TApplication.Trackmouse gets confused. }
-
- CatchFailures(fi, HandleFailure);
- gApplication.InvalidateFocus; { MacApp gets confused when tracking on the desktop. }
- Assertion(aView.Focus, AtStr(kFocusFailed));
- Success(fi);
-
- theVMouse := aVPt;
- theMouse := VPtToPt(theVMouse);
- GlobalToLocal(theMouse);
- PtToVPt(theMouse, theVMouse);
- DesktopToLocal := theVMouse;
-
- { Restore the desktopPort. }
- gApplication.InvalidateFocus;
- SetPort(savedPort)
-
- END
- ELSE
- DesktopToLocal := aVPT
-
- END; {DesktopToLocal}
-
- PROCEDURE NextView (aVPt: VPoint);
-
- { Returns the next tracking view, NIL if on desktop. }
-
- VAR
-
- theMouse : Point;
- aWMgrWindow : WindowPtr;
- trackingView : TView;
- thisView : TView;
- thisWindow : TWindow;
-
- FUNCTION ContainsPt (aView: TView): BOOLEAN;
-
- { Does this view contain the current tracking point? Used as an iterator. }
-
- VAR
- theVMouse: VPoint;
-
- BEGIN {ContainsPt}
- theVMouse := DesktopToLocal(aView.GetWindow, aVPt);
- aView.WindowToLocal(theVMouse);
- ContainsPt := aView.ContainsMouse(theVMouse);
- END; {ContainsPt}
-
- FUNCTION LastViewUnderPt (aView: TView): TView;
-
- { Recursively determine the topmost view under the current tracking point. }
-
- VAR
- subView: TView;
-
- BEGIN {LastViewUnderPt}
- LastViewUnderPt := aView;
- subView := aView.LastSubViewThat(ContainsPt);
- IF subView <> NIL THEN
- LastViewUnderPt := LastViewUnderPt(subView)
- END; {LastViewUnderPt}
-
- BEGIN {NextView}
-
- theMouse := VPtToPt(aVPt);
- IF FindWindow(theMouse, aWMgrWindow) = inContent THEN { We're in a window. }
- BEGIN
- thisWindow := gApplication.WMgrToWindow(aWMgrWindow);
- IF thisWindow = NIL THEN { Not a MacApp Window. }
- thisView := NIL
- ELSE IF thisWindow = fTrackingWindow THEN { A MacApp Window and same as last time. }
- IF ContainsPt(fTrackingView) THEN { Same view as last time. }
- thisView := LastViewUnderPt(fTrackingView)
- ELSE { Different view from last time. }
- thisView := LastViewUnderPt(thisWindow)
- ELSE { Different window from last time. }
- thisView := LastViewUnderPt(thisWindow)
- END
- ELSE { Not in a window. }
- BEGIN
- thisWindow := NIL;
- thisView := NIL
- END;
-
- fTrackingWindow := thisWindow;
- fTrackingView := thisView
-
- END; {NextView}
-
- BEGIN {TInterViewTracker.TrackMouse}
-
- TrackMouse := INHERITED TrackMouse(aTrackPhase,
- anchorPoint,
- previousPoint,
- nextPoint,
- mouseDidMove);
-
- IF (aTrackPhase = trackMove) & mouseDidMove THEN
- NextView(nextPoint) { Get the current fTrackingView and fTrackingWindow under the tracking point. }
- ELSE IF aTrackPhase = trackRelease THEN
- IF fTrackingView <> NIL THEN
- fReleasePoint := DesktopToLocal(fTrackingView, nextPoint)
- ELSE
- TrackMouse := gNoChanges;
-
- { This has to go here because MacApp's mouse tracking
- architecture wasn't intended for cross-view tracking. }
-
- aPoint := VPtToPt(nextPoint);
-
- { Do the coordinate translation and offset
- then use TCIconTrackers tracking method. }
-
- AddPt(fMouseDownOffset, aPoint);
-
- SELF.CIconTrack(aPoint)
-
- END; {TInterViewTracker.TrackMouse}
-
-
- {$S ADoCommand}
- PROCEDURE TInterViewTracker.DoIt;
- OVERRIDE;
-
- {$IFC qDebug}
- VAR
- className : MAName;
- {$ENDC}
-
-
- BEGIN {TInterViewTracker.DoIt}
- IF fTrackingView <> NIL THEN
- BEGIN
- gApplication.InvalidateFocus; { MacApp gets confused when tracking on the desktop. }
-
- { This is gross but nececessary because we don't have multiple
- inheritance and not everything can be a subclass of TTrackingView. }
-
- {$IFC qDebug}
- WRITE('fTrackingView is a ');
- IF fTrackingView <> NIL THEN
- BEGIN
- fTrackingView.GetClassName(className);
- WRITELN(className)
- END
- ELSE
- WRITELN('NIL');
- {$ENDC}
-
-
- { Probably you will want to override this DoIt and test the membership
- of the view onto which the icon was dropped. This is groddy, but without
- multilple inheritance....
-
- Your code might look like this:
-
- VAR
- releasePoint : VPoint;
-
- releasePoint := fReleasePoint;
-
- IF MEMBER(fTrackingView, TCGridView1) THEN
- TMyView1(fTrackingView).PlaceIcon(fIconNumber, releasePoint, PlaceIt)
- ELSE IF MEMBER(fTrackingView, TCGridView2) THEN
- TMyView2(fTrackingView).PlaceIcon(fIconNumber, releasePoint, PlaceIt)
- ELSE IF MEMBER(fTrackingView, TCGridView2) THEN
- TMyView3(fTrackingView).SomeOtherMethod(fIconNumber, PlaceIt) }
-
- END
-
- END; {TInterViewTracker.DoIt}
-
-
- { ::::::::::::: TPlaceByNumber ::::::::::::::: }
-
-
- {$S ASelCommand}
- PROCEDURE TPlaceByNumber.IPlaceByNumber (aTrackingView: TView;
- offset: Point;
- anIconNumber: IconNumber);
-
- BEGIN {TPlaceByNumber.IPlaceByNumber}
- fIconNumber := anIconNumber;
- SELF.IInterViewTracker(aTrackingView, offset);
- END; {TPlaceByNumber.IPlaceByNumber}
-
-
- {$S AFields}
- PROCEDURE TPlaceByNumber.Fields (PROCEDURE DoToField (fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
-
- BEGIN {TPlaceByNumber.Fields}
- DoToField('TPlaceByNumber', NIL, bClass);
- DoToField('fIconNumber', @fIconNumber, bInteger);
- INHERITED Fields(DoToField);
- END; {TPlaceByNumber.Fields}
-
-
- {$S ASelCommand}
- FUNCTION TPlaceByNumber.GetCIconHandle: CIconHandle;
- OVERRIDE;
-
- VAR
- tempCIcon: CIconHandle;
-
- BEGIN
- tempCIcon := GetCIcon(fIconNumber);
- FailNILResource(tempCIcon);
- GetCIconHandle := tempCIcon;
- END;
-
-
- {$S ADoCommand}
- PROCEDURE TPlaceByNumber.DoIt;
- OVERRIDE;
-
- VAR
- releasePoint : VPoint;
-
- BEGIN {TPlaceByNumber.DoIt}
- INHERITED DoIt;
-
- IF fTrackingView <> NIL THEN
- BEGIN
- releasePoint := fReleasePoint;
-
- IF MEMBER(fTrackingView, TTrackingView) THEN
- TTrackingView(fTrackingView).PlaceIcon(fIconNumber, releasePoint, PlaceIt);
-
- { Probably you will want to override this DoIt and test the membership
- of the view onto which the icon was dropped. This is groddy, but without
- multilple inheritance....
-
- Your code might look like this:
-
- IF MEMBER(fTrackingView, TCGridView1) THEN
- TMyView1(fTrackingView).PlaceIcon(fIconNumber, releasePoint, PlaceIt)
- ELSE IF MEMBER(fTrackingView, TCGridView2) THEN
- TMyView2(fTrackingView).PlaceIcon(fIconNumber, releasePoint, PlaceIt)
- ELSE IF MEMBER(fTrackingView, TCGridView2) THEN
- TMyView3(fTrackingView).SomeOtherMethod(fIconNumber, PlaceIt) }
-
- END;
- END; {TPlaceByNumber.DoIt}
-
-
- {$S ADoCommand}
- PROCEDURE TPlaceByNumber.UndoIt;
- OVERRIDE;
-
- VAR
- releasePoint : VPoint;
-
- BEGIN {TPlaceByNumber.UndoIt}
- IF fTrackingView <> NIL THEN
- BEGIN
- releasePoint := fReleasePoint;
-
- { This is gross but nececessary because we don't have multiple
- inheritance and not everything can be a subclass of TTrackingView.
- See comments in TPlaceByNumber.DoIt. }
-
- IF MEMBER(fTrackingView, TTrackingView) THEN
- TTrackingView(fTrackingView).PlaceIcon(fIconNumber, releasePoint, UnPlaceIt);
-
- END;
- END; {TPlaceByNumber.UndoIt}
-
-
- {$S ADoCommand}
- PROCEDURE TPlaceByNumber.RedoIt;
- OVERRIDE;
-
- VAR
- releasePoint : VPoint;
-
- BEGIN {TPlaceByNumber.RedoIt}
- IF fTrackingView <> NIL THEN
- BEGIN
- releasePoint := fReleasePoint;
-
- { This is gross but nececessary because we don't have multiple
- inheritance and not everything can be a subclass of TTrackingView.
- See comments in TPlaceByNumber.DoIt. }
-
-
- IF MEMBER(fTrackingView, TTrackingView) THEN
- TTrackingView(fTrackingView).PlaceIcon(fIconNumber, releasePoint, RePlaceIt);
-
- END;
- END; {TPlaceByNumber.RedoIt}
-
-